﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace XHXTools
{
    /// <summary>
    /// 读写文本、文件
    /// </summary>
    public class RWTextToFile
    {
        /// <summary>
        /// 将日志文本写入文件中
        /// </summary>
        /// <param name="logTxt">文本内容</param>
        /// <param name="logFilePath">文件路径</param>
        /// <param name="logFileName">文件的名称</param>
        /// <returns>返回一个文件流</returns>
        public static void WriterLog(string logTxt,string logFilePath, string logFileName)
        {
            try
            {
                if (!Directory.Exists(logFilePath)) Directory.CreateDirectory(logFilePath);
                if (!File.Exists(Path.Combine(logFilePath, logFileName)))
                {
                    File.CreateText(Path.Combine(logFilePath, logFileName)).Dispose();
                }

                StreamWriter sw = new StreamWriter(Path.Combine(logFilePath, logFileName), true, Encoding.UTF8);
                sw.WriteLine(logTxt);
                sw.Close();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
